#pragma once
#include <string.h>
#include <iostream>
#include "boost/process.hpp"
#include "boost/process/windows.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/fstream.hpp"


static std::vector<char> get_file_data(std::string file_path)
{
	std::ifstream file(file_path, std::ios_base::binary);
	/*assert(file.good());*/
	if (!file.good())
	{
		std::cout << "get_file_data fail : " << file_path.c_str() << std::endl;
		return std::vector<char>();
	}
	file.seekg(0, std::ios_base::end);
	int file_len = file.tellg();
	file.seekg(0, std::ios_base::beg);

	std::vector<char> data(file_len, 0);
	file.read(data.data(), file_len);

	file.close();
	return data;
}

static void write_file_data(std::vector<char> data, std::string file_path)
{
	std::ofstream file(file_path, std::ios_base::binary);
	file.write(data.data(), data.size());
	file.close();
}

static std::vector<std::string> EnumFiles(std::string path, std::string extension)
{
	namespace fs = boost::filesystem;
	fs::path _path(path);
	fs::path fullpath = fs::system_complete(_path);

	std::vector<std::string> ret;

	if (!fs::exists(fullpath) && !fs::is_directory(fullpath))
	{
		return ret;
	}
	fs::directory_iterator end_iter;
	for (fs::directory_iterator iter(fullpath); iter != end_iter; iter++)
	{
		try {
			if (fs::is_directory(*iter))
			{
				//ret.push_back(iter->path().wstring());
			}
			else if (iter->path().extension() == extension)
			{
				ret.push_back(iter->path().string());
			}
		}
		catch (const std::exception&)
		{
			continue;
		}
	}
	return ret;
}